package DAO;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;


public class HibernateUtil {
	
	private static EntityManagerFactory emf = Persistence.createEntityManagerFactory("myapp");
	
	public static EntityManager getSession() {
		EntityManager em = emf.createEntityManager();
    	return em;
    }
	
	public static EntityManager beginTransaction() {
		EntityManager em = HibernateUtil.getSession();
		em.getTransaction().begin();
		return em;
	}
	
	public static void commitTransaction() {
		EntityManager em = HibernateUtil.getSession();
		em.getTransaction().commit();
    }    	 
	    
	public static void rollbackTransaction() {
		EntityManager em = HibernateUtil.getSession();
   	 	em.getTransaction().rollback();
    }   	 
	    
	public static void closeSession() {
		EntityManager em = HibernateUtil.getSession();
		em.close();
    }	    
}

